package com.ym521.freesnack.utils

import android.content.Context
import android.view.View

/**
 *@author Ym
 *E-mail: 2435970206@qq.com
 *createTime:2024/3/2
 *explain:
 *
 */
internal object PixelUtil {

    fun dip2px(view: View, dpValue: Float): Int {
        return dip2px(view.context, dpValue)
    }

    fun dip2px(mContext: Context, dpValue: Float): Int {
        val scale: Float = mContext.resources.displayMetrics.density
        return (dpValue * scale + 0.5f).toInt()
    }

    fun px2dip(view: View, dpValue: Float): Int {
        return px2dip(view.context, dpValue)
    }

    fun px2dip(mContext: Context, pxValue: Float): Int {
        val scale: Float = mContext.resources.displayMetrics.density
        return (pxValue / scale + 0.5f).toInt()
    }
}